/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OntologyEvaluation.java
 *
 * Created on Apr 9, 2011, 11:02:01 AM
 */

package au.edu.latrobe.placecomm.utils;

import edu.stanford.smi.protege.model.KnowledgeBase;
import edu.stanford.smi.protege.model.Project;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author Tuan Nguyen
 */
public class OntologyEvaluation extends javax.swing.JDialog {


    // Variables
     Project prj;
     KnowledgeBase kb;

    /** Creates new form OntologyEvaluation */
    public OntologyEvaluation(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LoadOWLFileBtn = new javax.swing.JButton();
        OntologyFilenameTF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        SOVbtn = new javax.swing.JButton();
        ENRbtn = new javax.swing.JButton();
        TIPbtn = new javax.swing.JButton();
        DITbtn = new javax.swing.JButton();
        SOVtf = new javax.swing.JTextField();
        TIPtf = new javax.swing.JTextField();
        ENRtf = new javax.swing.JTextField();
        CODtf = new javax.swing.JTextField();
        NOCtf = new javax.swing.JTextField();
        CODbtn = new javax.swing.JButton();
        CIDbtn = new javax.swing.JButton();
        CIDtf = new javax.swing.JTextField();
        NOCbtn = new javax.swing.JButton();
        EOGtf = new javax.swing.JTextField();
        EOGbtn = new javax.swing.JButton();
        DITtf = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ExitBtn = new javax.swing.JButton();
        CalcAllBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        LoadOWLFileBtn.setText("Load");
        LoadOWLFileBtn.setToolTipText("Load OWL File");
        LoadOWLFileBtn.setName("LoadOWLFileBtn"); // NOI18N
        LoadOWLFileBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                LoadOWLFileBtnMouseClicked(evt);
            }
        });

        OntologyFilenameTF.setText("e:\\\\1Working\\\\1mythesis\\\\Appendix1\\\\pbvc.pprj");
        OntologyFilenameTF.setName("OntologyFilenameTF"); // NOI18N

        jLabel1.setText("Load Ontology");
        jLabel1.setName("jLabel1"); // NOI18N

        SOVbtn.setText("SOV");
        SOVbtn.setToolTipText("Size of Vocabulary");
        SOVbtn.setName("SOVbtn"); // NOI18N
        SOVbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SOVbtnMouseClicked(evt);
            }
        });

        ENRbtn.setText("ENR");
        ENRbtn.setToolTipText("Edge Node Ratio");
        ENRbtn.setName("ENRbtn"); // NOI18N
        ENRbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ENRbtnMouseClicked(evt);
            }
        });

        TIPbtn.setText("TIP");
        TIPbtn.setToolTipText("Tree Impurity");
        TIPbtn.setName("TIPbtn"); // NOI18N
        TIPbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TIPbtnMouseClicked(evt);
            }
        });

        DITbtn.setText("DIT");
        DITbtn.setToolTipText("Depth of inheritance");
        DITbtn.setName("DITbtn"); // NOI18N

        SOVtf.setName("SOVtf"); // NOI18N

        TIPtf.setName("TIPtf"); // NOI18N

        ENRtf.setName("ENRtf"); // NOI18N

        CODtf.setName("CODtf"); // NOI18N

        NOCtf.setName("NOCtf"); // NOI18N

        CODbtn.setText("COD");
        CODbtn.setToolTipText("Class-out Degree");
        CODbtn.setName("CODbtn"); // NOI18N

        CIDbtn.setText("CID");
        CIDbtn.setToolTipText("Class-in Degree");
        CIDbtn.setName("CIDbtn"); // NOI18N

        CIDtf.setName("CIDtf"); // NOI18N

        NOCbtn.setText("NOC");
        NOCbtn.setToolTipText("Number of Children");
        NOCbtn.setName("NOCbtn"); // NOI18N

        EOGtf.setName("EOGtf"); // NOI18N

        EOGbtn.setText("EOG");
        EOGbtn.setToolTipText("Entropy of Graph");
        EOGbtn.setName("EOGbtn"); // NOI18N
        EOGbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                EOGbtnMouseClicked(evt);
            }
        });

        DITtf.setName("DITtf"); // NOI18N

        jLabel2.setText("Ontology-level Metrics");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("Class-level Metrics");
        jLabel3.setName("jLabel3"); // NOI18N

        ExitBtn.setText("Exit");
        ExitBtn.setName("ExitBtn"); // NOI18N
        ExitBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ExitBtnMouseClicked(evt);
            }
        });

        CalcAllBtn.setText("Calculate All");
        CalcAllBtn.setName("CalcAllBtn"); // NOI18N
        CalcAllBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CalcAllBtnMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(CIDbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(NOCbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(CIDtf)
                                            .addComponent(NOCtf, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(CalcAllBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(DITbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(CODbtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(ExitBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(CODtf, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                                    .addComponent(DITtf, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(SOVbtn, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                                    .addComponent(TIPbtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(SOVtf)
                                    .addComponent(TIPtf, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(EOGbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(ENRbtn))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(EOGtf, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                                    .addComponent(ENRtf, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(OntologyFilenameTF, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LoadOWLFileBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(56, 56, 56))
                    .addComponent(jLabel3))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OntologyFilenameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(LoadOWLFileBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(SOVbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(SOVtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TIPbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(TIPtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(ENRtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addComponent(EOGtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ENRbtn)
                        .addGap(29, 29, 29))
                    .addComponent(EOGbtn))
                .addGap(24, 24, 24)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(NOCtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(DITbtn)
                            .addComponent(DITtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(CODbtn)
                                .addComponent(CODtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(CIDtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(NOCbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CIDbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ExitBtn)
                    .addComponent(CalcAllBtn))
                .addGap(60, 60, 60))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ExitBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ExitBtnMouseClicked
        // TODO add your handling code here:
        System.exit(0);
        
    }//GEN-LAST:event_ExitBtnMouseClicked

    private void LoadOWLFileBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LoadOWLFileBtnMouseClicked

        //Loading Ontology
        String sProjectFullPath=OntologyFilenameTF.getText();
        Collection errors = new ArrayList();
        prj = Project.loadProjectFromFile(sProjectFullPath,errors);
        kb  = prj.getKnowledgeBase();
                
    }//GEN-LAST:event_LoadOWLFileBtnMouseClicked

    private void SOVbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SOVbtnMouseClicked
        /* 
         * G = <N,P,E>
         * SOV = Nn + Pn
         * where Nn repreentin named classed and individuals,
         * Pn representing user-defined properties.
         */
        int iSOV=0;
        int iNn = kb.getClsCount();
        Collection colInstances = kb.getInstances();
        Iterator iter = colInstances.iterator();
        int iInstances  = 0;
        while (iter.hasNext()) {
            iInstances++;
            iter.next();
        }
        iNn = iNn + iInstances ;
        int iPn = kb.getSlotCount();
        iSOV = iNn + iPn; 
        String s= Integer.toString(iSOV);
        SOVtf.setText(s);
    }//GEN-LAST:event_SOVbtnMouseClicked

    private void ENRbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ENRbtnMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_ENRbtnMouseClicked

    private void TIPbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TIPbtnMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_TIPbtnMouseClicked

    private void EOGbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_EOGbtnMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_EOGbtnMouseClicked

    private void CalcAllBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CalcAllBtnMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_CalcAllBtnMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                OntologyEvaluation dialog = new OntologyEvaluation(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CIDbtn;
    private javax.swing.JTextField CIDtf;
    private javax.swing.JButton CODbtn;
    private javax.swing.JTextField CODtf;
    private javax.swing.JButton CalcAllBtn;
    private javax.swing.JButton DITbtn;
    private javax.swing.JTextField DITtf;
    private javax.swing.JButton ENRbtn;
    private javax.swing.JTextField ENRtf;
    private javax.swing.JButton EOGbtn;
    private javax.swing.JTextField EOGtf;
    private javax.swing.JButton ExitBtn;
    private javax.swing.JButton LoadOWLFileBtn;
    private javax.swing.JButton NOCbtn;
    private javax.swing.JTextField NOCtf;
    private javax.swing.JTextField OntologyFilenameTF;
    private javax.swing.JButton SOVbtn;
    private javax.swing.JTextField SOVtf;
    private javax.swing.JButton TIPbtn;
    private javax.swing.JTextField TIPtf;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables

}
